/*
 *
 * @ProjectName:    my_umi_app
 * @Package:
 * @ClassName:      category_api
 * @Description:    Category——api
 * @Author:         SuPeiSen
 * @CreateDate:     2021/1/7 11:00 下午
 * @UpdateDate:     2021/1/7 11:00 下午
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */

// 删除栏目
import { AxiosParam, Requests } from '@/utils/requests';
import { ApiPath } from '@/config/api_config';
import { CategoryItemAdminType, CategoryListAdminType } from '@/type/category';
import { MenuListModel } from '@/type/menu_type';

// 获取分类
export const getCategoryByAdminApi = async (postParam: AxiosParam) => {
  return await Requests.defaults.http<CategoryListAdminType>(
    'get',
    ApiPath.getAllCategoryByAdmin,
  );
};

// 获取所有分类(不分页)
export const getCategoryApi = async (finallyCallBack: () => void) => {
  return await Requests.defaults.http<Array<CategoryItemAdminType>>(
    'get',
    ApiPath.getAllCategory,
    {
      callBack: {
        finally: finallyCallBack,
      },
    },
  );
};

// 添加分类
export const addCategoryByAdminApi = async (
  postParam: any,
  finallyCallBack: () => void,
) => {
  return await Requests.defaults.http('post', ApiPath.addCategoryByAdmin, {
    postData: postParam,
    callBack: {
      finally: finallyCallBack,
    },
  });
};

// 更新分类
export const updateCategoryApi = async (postParam: any) => {
  const model = await Requests.defaults.http<MenuListModel>(
    'put',
    ApiPath.updateCategory,
    {
      postData: postParam,
    },
  );
  return model.success;
};

// 删除分类
export const deleteCategoryApi = async (id: number) => {
  const model = await Requests.defaults.http<MenuListModel>(
    'delete',
    ApiPath.deleteCategory + `/${id}`,
  );
  return model.success;
};
